package algorithm.swordoff;

/**
 * 和为s的两个数字
 * 两数之和
 */

public class SQ57 {
    public int[] twoSum(int[] nums, int target) {
        int begin = 0, end = nums.length-1;

        while (begin <= end) {
            if (nums[begin] + nums[end] == target) return new int[]{nums[begin], nums[end]};
            else if (nums[begin] + nums[end] < target) begin++;
            else end--;
        }
        return new int[]{};
    }

}
